package com.wildfire.util;

import java.io.UnsupportedEncodingException;

import org.apache.commons.codec.binary.Base64;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

public class TokenUtil {
    public static String encrypt(String userInfo) throws UnsupportedEncodingException{
        return Base64.encodeBase64String(userInfo.getBytes("utf-8"));
    }

    public static String decrypt(String encryptdUserInfo){
        return new String(Base64.decodeBase64(encryptdUserInfo));
    }
    public static void main(String[] args) throws UnsupportedEncodingException {
		JSONObject userObject = new JSONObject();
        userObject.put("user", "admin");
        userObject.put("pass", "admin");
        System.out.println(encrypt(JSON.toJSONString(userObject)));
        System.out.println(decrypt("eyJwYXNzIjoiMDIxMiIsInVzZXIiOiJ6d3h1In0="));
	}
    
}
